/**
 * 
 */
package com.dlplay.flightinfo.test;


import java.io.File;
import java.util.logging.Logger;


import javax.servlet.ServletException;

import org.junit.AfterClass;
import org.junit.BeforeClass;

import com.dlplay.flightinfo.core.FlightSystem;


import com.google.apphosting.api.ApiProxy;
import com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue;
import com.google.appengine.tools.development.ApiProxyLocalImpl;



/**
 * @author ZhangYu
 *
 */

public abstract class AbstractGaeTestSuite {

	protected static Logger log = Logger.getLogger(AbstractGaeTestSuite.class.getName());
	
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		//For GAE test env
		ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
        ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")){});
        
        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
        // prevent tasks from automatically executing
//        proxy.setProperty(LocalTaskQueue.SERVICE_NAME, Boolean.TRUE.toString());
//        LocalTaskQueue lta = new LocalTaskQueue();
//        lta.getPackage();
        
        //Local env
        FlightSystem fs = new FlightSystem();
		try {
			fs.init();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
		
//		LocalTaskQueue ltq = (LocalTaskQueue) proxy.getService(null);
        // clear out all tasks in all queues
//        for (String queueName : ltq.getQueueStateInfo().keySet()) {
//            ltq.flushQueue(queueName);
//        }
		
		// not strictly necessary to null these out but there's no harm either
        ApiProxy.setDelegate(null);
        ApiProxy.setEnvironmentForCurrentThread(null);
	}


	

}
